import request from './utils';
import { ApiData } from './utils/axiosWrapper';

interface AddFaultBody {
  name: string;
  reasons: {
    name: string;
    solution: string;
  }[];
}
/**
 * 添加
 * @param params
 */
export const requestAddFault = (params: AddFaultBody): Promise<ApiData<boolean>> => {
  return request.post('/api/fault', params);
};

export interface GetFaultReturnData {
  _id: string;
  name: string;
  reasons: {
    name: string;
    solution: string;
  }[];
}
/**
 * 列表
 */
export const requestGetFault = (): Promise<ApiData<GetFaultReturnData[]>> => {
  return request.get('/api/fault');
};

/**
 * 详情
 * @param id
 */
export const requestGetFaultInfo = (id: string): Promise<ApiData<GetFaultReturnData>> => {
  return request.get(`/api/fault/${id}`);
};

/**
 * 删除
 * @param id
 */
export const requestDeleteFault = (id: string): Promise<ApiData<boolean>> => {
  return request.delete(`/api/fault/${id}`);
};

export interface EditFaultParams extends AddFaultBody {
  id: string;
}
/**
 * 修改
 * @param id
 */
export const requestEditFault = (params: EditFaultParams): Promise<ApiData<boolean>> => {
  const { id, ...rest } = params;
  return request.put(`/api/fault/${id}`, { ...rest });
};
